package edu.gatech.cs2340.bytebankers.model;

import java.io.Serializable;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

import com.sun.org.apache.bcel.internal.generic.NEW;

import edu.gatech.cs2340.bytebankers.model.item.ItemManager;
import edu.gatech.cs2340.bytebankers.model.state.*;

public class Journey implements Serializable {
	
	private int pace;
	private int rationRate;
	private Leader leader;
	private List<Player> players;
	private Wagon wagon;
	private Trail trail;
	private GameState gameState;
	private ErrorState errorState;
	private ItemManager itemManager;
	private int distanceTraveled;
	private Date date;
	private DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
	private Location location;
	private int distanceTraveledfromLastLocation;
	
	public Journey() {
		players = new ArrayList<Player>();
		distanceTraveled = 0;
		date = new Date(df.format(new Date(1848, 3, 20)));
		itemManager = new ItemManager();
		trail = new Trail();
		this.setLastLocation(this.trail.getLocationList().getFirst());
	}
	
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public int getDistanceTraveled() {
		return distanceTraveled;
	}

	public void setDistanceTraveled(int distanceTraveled) {
		this.distanceTraveled = distanceTraveled;
	}

	/**
	 * Getter for the pace.
	 * @return The pace.
	 */
	public int getPace() {
		return pace;		
	}
	
	/**
	 * Setter for the pace.
	 * @param pace The pace.
	 */
	public void setPace(int pace) {
		this.pace = pace;
		System.out.println("Set pace to " + pace);
	}
	
	/**
	 * Getter for the ration rate.
	 * @return The rate.
	 */
	public int getRationRate() {
		return rationRate;
	}
	
	/**
	 * Setter for ration rate.
	 * @param rationRate The ration rate to set.
	 */
	public void setRationRate(int rationRate) {
		this.rationRate = rationRate;
		System.out.println("Set ration rate to " + rationRate);
	}
	
	/**
	 * Getter for the leader.
	 * @return The leader.
	 */
	public Leader getLeader() {
		return leader;
	}
	
	/**
	 * Setter for the leader.
	 * @param leader The leader.
	 */
	public void setLeader(Leader leader) {
		this.leader = leader;
		System.out.println("Set leader to: " + leader);
	}
	
	/**
	 * Getter for the players.
	 * @return The players.
	 */
	public List<Player> getPlayers() {
		return players;
	}
	
	/**
	 * Adds a player.
	 * @param player The player to add.
	 */
	public void addPlayer(Player player) {
		players.add(player);
	}
	
	/**
	 * Kills a player.
	 * @param player The player to add.
	 */
	public void killPlayer(Player player) {
		players.remove(player);
	}
	
	public void setIllPlayer(Player player, String status) {
		player.setsickStatus(status);
	}
	
	
	/**
	 * Getter for the wagon.
	 * @return The wagon.
	 */
	public Wagon getWagon() {
		return wagon;
	}
	
	/**
	 * Setter for the wagon.
	 * @param wagon The wagon to add.
	 */
	public void setWagon(Wagon wagon) {
		this.wagon = wagon;
	}
	
	/**
	 * Getter for the trail.
	 * @return The trail.
	 */
	public Trail getTrail() {
		return trail;
	}
	
	/**
	 * Seter for the trail.
	 * @param trail The trail to set.
	 */
	public void setTrail(Trail trail) {
		this.trail = trail;
	}
	
	/**
	 * Getter for the game state.
	 * @return the game state.
	 */
	public GameState getGameState() {
		return gameState;
	}
	
	/**
	 * Setter for the game state.
	 * @param gameState The game state to set.
	 */
	public void setGameState(GameState gameState) {
		this.gameState = gameState;
	}
	
	/**
	 * Getter for the error state.
	 * @return The error state.
	 */
	public ErrorState getErrorState() {
		return errorState;
		
	}
	
	/**
	 * Setter for the error state.
	 * @param errorState The error state to get.
	 */
	public void setErrorState(ErrorState errorState) {
		this.errorState = errorState;
	}

	/**
	 * Getter for the item manager.
	 * @return The item manager.
	 */
	public ItemManager getItemManager() {
		return itemManager;
	}

	/**
	 * Setter for the item manager.
	 * @param errorState The item manager to get.
	 */
	public void setItemManager(ItemManager itemManager) {
		this.itemManager = itemManager;
	}
	
	/**
	 * Setter for location
	 */
	public void setLastLocation(Location location){
	    this.location = location;
	}
	
	/**
	 * Getter for location
	 * @return last town location of players
	 */
	public Location getlastLocation() {
	    return location;
	}
	
	/**
	 * Getter for last location
	 * @return int distance from last location visited
	 */
	public int getDistanceFromLastLocation() {
	    return distanceTraveledfromLastLocation;
	}
	
	/**
	 * Setter for distance from last location visited
	 * @param distance 
	 */
	public void setDistanceFromLastLocation(int distance) {
	    distanceTraveledfromLastLocation = distance;
	}
}
